package com.itzmn.newcode.offer;

/**
 * @Author: 张梦楠
 * @Date: 2018/11/17 13:28
 * 简书：https://www.jianshu.com/u/d611be10d1a6
 * 码云：https://gitee.com/zhangqiye
 * @Description: 剑指Offer，得到指定数字在有序数组中出现的次数
 *
 */
public class GetNumCountOfArray {

    public static void main(String[] args) {

        new GetNumCountOfArray().GetNumberOfK(new int[]{1,2,2,2,3,3,4,5},2);
    }


    public int GetNumberOfK(int [] array , int k) {

        int j=0;
        boolean t = false;
        for (int i=0;i<array.length;i++){
            if (array[i]==k){
                j++;
                t = true;
            }
            if (t && array[i] !=k){
                break;
            }
        }
        return j;

    }


}
